/*
 * Copyright (C) 2009,2010,2011  Paulo Cesar Pereira de Andrade.
 *
 * This is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * Authors:
 *	Paulo Cesar Pereira de Andrade
 */

#ifndef _ecfg_h
#define _ecfg_h

#include <setjmp.h>

#include "etypes.h"

#define ecfg_error(fallback, format, ...)				\
    do {								\
	if (cfg_note)							\
	    enote_error(cfg_note, format, ## __VA_ARGS__);		\
	e##fallback##_error(null, format, ## __VA_ARGS__);		\
    } while (0)

#define ecfg_warn(fallback, format, ...)				\
    do {								\
	if (cfg_note)							\
	    enote_warn(cfg_note, format, ## __VA_ARGS__);		\
	else								\
	    e##fallback##_warn(null, format, ## __VA_ARGS__);		\
    } while (0)

#define ecode_nil()			cfg_nil_node
#define immediate_int(node)		(node)->cimmediate.data.L
#define immediate_float(node)		(node)->cimmediate.data.F
#define immediate_lo(node)		(node)->cimmediate.data.s.l
#define immediate_hi(node)		(node)->cimmediate.data.s.h
#define immediate_offset(node)		immediate_lo(node)

/*
 * Prototypes
 */
PUBLIC extern int
ecfg_main(int argc, char *argv[]);

extern void
ecfg(void);

extern east_node_t *
ecode_int(eint_t value);

extern east_node_t *
ecode_float(efloat_t value);

extern east_node_t *
ecode_literal(eint32_t offset);

extern east_node_t *
ecode_switch(void);

extern ebool_t
ecfg_implicit_used_p(east_list_t *list);

extern void
init_cfg(void);

/*
 * Externs
 */
extern east_node_t	*cfg_note;
extern eint32_t		 cfg_pass;
extern eint32_t		 cfg_optsize;
extern eint32_t		 cfg_optlevel;
extern eint32_t		 cfg_verbose;
extern eint32_t		 cfg_float_format;
extern mp_prec_t	 cfg_mpfr_prc;
extern mp_rnd_t		 cfg_mpfr_rnd;
extern char		*cfg_progname;
extern east_node_t	*cfg_nil_node;
extern sigjmp_buf	 cfg_env;

#endif /* _ecfg_h */
